import { Controller, Inject, Get, Query, Param, Del, Post } from '@midwayjs/core';
import { OperLogService } from "@service/monitor/operLog.service";
import { ListOperLogDTO } from "@dto/monitor/operLog.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/monitor/operlog')
export class PostController {
  @Inject()
  operLogService: OperLogService;

  // 获取列表
  @Auth('monitor:operlog:list')
  @Get('/list')
  async list(@Query() queryParams: ListOperLogDTO) {
    return await this.operLogService.list(queryParams);
  }

  // 删除
  @Auth('monitor:operlog:remove')
  @Log({ title: '操作日志', businessType: BusinessType.REMOVE })
  @Del('/:operId')
  async delete(@Param('operId') operId: string) {
    return await this.operLogService.delete(operId);
  }

  // 获取详情
  @Auth('monitor:operlog:query')
  @Get('/:operId')
  async get(@Param('operId') operId: number) {
    return await this.operLogService.detail(operId);
  }

  // 导出
  @Auth('monitor:operlog:export')
  @Log({ title: '操作日志', businessType: BusinessType.EXPORT })
  @Post('/export')
  async export(@Query() queryParams: ListOperLogDTO) {
    return await this.operLogService.export(queryParams);
  }

  // 清空所有数据
  @Auth('monitor:operlog:clean')
  @Log({ title: '操作日志', businessType: BusinessType.CLEAR })
  @Del('/clean')
  async clean() {
    return await this.operLogService.clean();
  }
}
